/**
 * loginLog.html page script
 * @author czp
 * date 2018-05-01
 */
var autoHeight = window.innerHeight;
$('.autoHeight').height(autoHeight - 90);

$('.i-checks').iCheck({
    checkboxClass: 'icheckbox_square-green',
    radioClass: 'iradio_square-green'
});
var start = {
    elem: '#start',
    format: 'YYYY-MM-DD hh:mm:ss',
    min: laydate.now(),
    max: '2099-06-16 23:59:59',
    istime: true,
    istoday: false,
    choose: function (datas) {
        end.min = datas;
        end.start = datas
    }
};
var end = {
    elem: '#end',
    format: 'YYYY-MM-DD hh:mm:ss',
    min: laydate.now(),
    max: '2099-06-16 23:59:59',
    istime: true,
    istoday: false,
    choose: function (datas) {
        start.max = datas;
    }
};
laydate(start);
laydate(end);

$.jgrid.defaults.styleUI = 'Bootstrap';

$("#table_list_2").jqGrid({
    datatype: "json",
    mtype : "POST",
    url : contextPath + "/manage/getSysLogs",
    jsonReader : {
        page : "page", // 数据页码
        total : "total", // 总页码
        records : "records", // 总共有多少条数据
        root : "rows", // 数据模型
        repeatitems : false
    },
    height: ( autoHeight - 270 ),
    autowidth: true,
    sortorder : "desc",
    rowNum: 20,
    rowList: [ 10, 20, 30, 40, 50 ],
    colNames: [ '时刻', '用户', 'IP地址', '浏览器', '登陆动作' ],
    colModel: [
        { name: 'timeStr', index: 'timeStr', editable: true, width: 60 },
        { name: 'c_staff_name', index: 'c_staff_name', editable: true, width: 60 },
        { name: 'c_login_ip', index: 'c_login_ip', editable: true, width: 60 },
        { name: 'c_browser_type', index: 'c_browser_type', editable: true, width: 80 },
        { name: 'c_state', index: 'c_state', editable: true, width: 60 }
    ],
    pager: "#pager_list_2",
    viewrecords: true,
    add: true,
    edit: true,
    addtext: 'Add',
    edittext: 'Edit',
    hidegrid: false
});

$("#table_list_2").setSelection(4, true);

$("#table_list_2").jqGrid('navGrid', '#pager_list_2', {
    edit: false,
    add: false,
    del: false,
    search: false
}, {
    height: 200,
    reloadAfterSubmit: true
});

$(window).bind('resize', function () {
    var width = $('.jqGrid_wrapper').width();
    $('#table_list_2').setGridWidth(width);
});

$('#find').on("click", function () {
    var action = $("input:checkbox[name='actionBox']:checked").map(function(index, elem) {
        return $(elem).val();
    }).get().join(' > ');
    var startTime = $('#start').val();
    var endTime = $('#end').val();
    var time;
    if (startTime === "" && endTime !== "") {
        time = endTime;
    } else if (startTime !== "" && endTime === "") {
        time = startTime;
    } else if (startTime !== "" && endTime !== "") {
        time = startTime + " > " + endTime;
    }
    console.log("++++++" + time + "++++++");
    console.log("------" + action + "------");
    jQuery("#table_list_2").jqGrid('setGridParam', {
        url : contextPath + "/manage/getSysLogs",
        page : 1,
        postData: {
            "loginAction" : action,
            "time" : time
        }
    }).trigger("reloadGrid");
});
